<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
  import './css/style.css'
  import {doGet} from '@/api/index.js'
  export default {
    data () {
      return {
        flag:true,
        clock:null,
      }
    },
    watch:
    {
      $route(newVal,oldVal)
      {
        if(oldVal.path=='/'||oldVal.path=='/guide'||oldVal.path=='/register')
        {
          if(newVal.path!=='/'&&newVal.path!=='/guide'&&newVal.path!=='/register')
          {
            this.clock=setInterval(()=>{
              if(this.flag){
                this.getInfo();
              }
            },1000);
          }
        }
        else
        {
          if(newVal.path=='/'||newVal.path=='/guide'||newVal.path=='/register')
          {
            clearInterval(this.clock);
            this.clock=null;
          }
        }
      }
    },
    
    created()
    {this.$store.commit("getUserInfo")},
  
    methods:{
      getInfo () {
        let that=this;
        let apiUrl = '/sys_openlookeng_cluster/queryTotalCluster'
        let param = {}
        this.flag = false
        doGet(apiUrl, param).then((response) => {
          let obj = response.data.data
          if (obj.clusterNum == 0) {
            if(that.$route.fullPath!="/guide"){
              that.$router.push('/guide')
            }
          }
          // setTimeout(()=>{
            that.flag = true;
          // },1000)
        })
      },
    }
  }
</script>

<style scoped>
  #app, html, body {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
</style>
